<template>
    <div class="">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i> 招聘列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
                <!-- tabs -->
                <div class="handle-tab">
                    <el-tabs v-model="activeTab" @tab-click="handleClick">
                        <el-tab-pane label="所有" name=1></el-tab-pane>
                        <el-tab-pane label="审核中" name=2></el-tab-pane>
                        <el-tab-pane label="审核不通过" name=3></el-tab-pane>
                        <el-tab-pane label="审核通过" name=4></el-tab-pane>
                    </el-tabs>
                </div>
                <div style="height:40px"></div>
                <el-form :inline="true"  class="demo-form-inline">
                     <el-form-item label="职位名称:">
                        <el-input v-model="postName" placeholder="请输入职位名称" clearable style="width:300px;"></el-input>
                    </el-form-item>
                    <el-form-item label="公司名称:">
                        <el-input v-model="companyName" placeholder="请输入公司名称" clearable style="width:300px;"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSelect"> &nbsp;&nbsp;查询&nbsp;&nbsp;  </el-button>
                        <!-- <el-button type="primary" @click="onResetting"> &nbsp;&nbsp;重置&nbsp;&nbsp;  </el-button> -->
                    </el-form-item>
                </el-form>
                <el-table :data="tableData"  style="width: 100%"   ref="multipleTable">
                    <el-table-column prop="id" label="ID" width="100" align="center">
                    </el-table-column>
                    <el-table-column prop="post_name" label="职位名称" width="480" align="center">
                    </el-table-column>
                    <el-table-column prop="enterprise_name" label="公司名称" width="480" align="center">
                    </el-table-column>
                    <el-table-column prop="status" label="审核状态" width="100" align="center">
                    </el-table-column>
                      <el-table-column prop="created_time" label="发表时间" width="200" align="center">
                    </el-table-column>
                    <el-table-column label="操作" align="center" >
                        <template slot-scope="scope" >
                            <el-button class="look" size="small" type="text" @click="handleLook(scope.$index, scope.row)">查看</el-button>
                            <el-button class="del" size="small" type="text"  @click="handleDelete(scope.$index, scope.row)" >删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="pagination" v-show="totalPages>1">
                    <el-pagination v-if="paginationShow" @current-change="handleCurrentChange" :current-page="currentPage" layout="prev, pager, next" :page-size="pageSize" :total="totalElements" background>
                    </el-pagination>
                </div>
                
        </div>
        <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow">确 定</el-button>
            </span>
        </el-dialog>
        <!-- / 删除提示框 -->
    </div>
</template>
<script>
import {getRecruitList,postDeleteRecruit,getRecruitDeatils,} from '@/api/recruit'
export default {
    name:"recruitList",
    data() {
        return {
            pageIndex:1,//当前页码
            pageSize:10,//每页10条
            totalElements:1,//默认的总条数
            totalPages:1,//默认的总页数
            tableData:[],//表格数据
            delIndex:0, //当前选中的下标
            delId:0,  //当前要删除的Id
            paginationShow:true,//重新显示分页
            delVisible:false, //默认dialog 不弹出
            postName:'', //职位名称
            companyName:'',//公司名称
            activeTab:'1',//tabs默认激活项
            value:1,//请求的状态类型 与activeTab关联 1所有、2审核中、3审核不通过、4审核通过
            currentPage:1,//当前页面的active状态 每次切换tabs 改变分页
        }
    },
    //实例创建
    created(){
        //
        this.getDate();
    },
    //计算属性
    computed:{

    },
    //方法
    methods: {
        //切换tabs标签页触发
        handleClick(tab, event) {
            // console.log(tab, event);
            this.value = tab.$options.propsData.name;//取激活状态值为请求数据类型
            this.pageIndex=1;
            this.currentPage=1;
            this.paginationShow = false   //分页器消失
            this.$nextTick(function () {
                //分页器重新加载 解决element 分页器的无法触发current-change事件 只限在tabs页 
                this.paginationShow = true  
            })
            this.getDate(); 
        },
        //获取数据
        getDate(){
            getRecruitList(this.value,this.postName,this.companyName,this.pageIndex,this.pageSize).then((response)=> {
                // console.log(response);
                if(response.code==200){
                    var data = response.data;//当前返回的数据
                    this.totalElements = data.total; //总条数
                    this.totalPages = Math.ceil(data.total/this.pageSize);//总页数
                    var data = response.data.list;//重新赋值数据
                    let ary = [];
                    for(let i = 0; i<data.length;i++){
                        var obj = {};
                        obj.id = data[i].id;
                        obj.post_name = data[i].post_name;
                        obj.enterprise_name = data[i].enterprise_name;
                        obj.city_name = data[i].city_name;
                        obj.created_time = data[i].created_time;

                        if(data[i].status == 0){
                            obj.status = "审核中" ;   
                        }else if(data[i].status == 1){
                             obj.status = "审核不通过"  ;   
                        }else if(data[i].status == 2){
                             obj.status = "审核通过"  ;   
                        }
                        ary.push(obj);
                    }
                    this.tableData = ary;
                    
                }else{
                    this.$notify.error({
                        title: '异常',
                        offset: 100,
                        message: response.msg
                    });
                }
            })
        },
        //发布
        urlAdd(){
            this.$router.push({ path:'/topic/add'})
        },
        //查询
        onSelect(){
            this.pageIndex =1;
            this.getDate();
        },
        //分页
        handleCurrentChange(val){
            this.pageIndex =val;
            this.currentPage = val;
            this.getDate();
        },
        //查看
        handleLook(index,row){
            //跳转到详情页
              if(row.id && row.id>0){//编辑状态
                this.$router.push({ path: '/recruit/details',query:{id:row.id}});
            }else{
                this.$notify.info({title: '提示',message: '获取详情ID失败，请重试！'});
            }              
        },
        //删除
        handleDelete(index,row){
            // console.log(index,row.id);
            if(row.id && row.id>0){
                this.delIndex =index;//要删除的下标
                this.delId = row.id; //要删除的ID
                this.delVisible = true; //显示兑换弹出框
                 //console.log(this.delVisible);
            }else{
                // console.log("没触发");
            }
        },
        // 确定删除
        deleteRow(){
            //console.log(this.delId)
            if(this.delId>0){
                console.log(this.delId)
                postDeleteRecruit(this.delId).then(response=>{
                    // console.log(response);
                    if(response.code==200){
                        this.tableData.splice(this.delIndex, 1);
                        this.$message.success('删除成功');
                        this.delVisible = false;
                    }else{
                        this.$notify.error({
                            title: '删除失败',
                            duration:2000,
                            message: '失败原因：'+response.data.msg
                        });
                    }
                    
                })
            }
            
        }
        
    }
}
</script>
<style lang="stylus" scoped>
    .edit{
        color #ff9800;
    }
    .del{
        color #e51c23;
    }
    .download{
        color #67C23A;
    }
</style>


